package com.extension.company.view.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.extension.company.admin.R;
import com.extension.company.model.entity.LeftListBean;

import java.util.List;

public class MakeMoneyLeftAdapter extends BaseAdapter {

	private Context context;
	private int index = 0;  // 当前选中的位置
	private List<LeftListBean.DataBean.CategoryBean> list;

	public MakeMoneyLeftAdapter(Context context, List<LeftListBean.DataBean.CategoryBean> list) {
		this.context = context;
		this.list = list;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder = null;
		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(R.layout.fragment_moneyleft_item, null);
			viewHolder = new ViewHolder();
			viewHolder.layout_main = convertView.findViewById(R.id.layout_main);
			viewHolder.m_view = convertView.findViewById(R.id.m_view);
			viewHolder.tv_content = convertView.findViewById(R.id.tv_content);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		if (position == index) { // 点击了相应的位置，相应的item颜色改变
			viewHolder.m_view.setVisibility(View.VISIBLE);
			viewHolder.tv_content.setTextColor(Color.parseColor("#FF8A0D"));
			viewHolder.layout_main.setBackgroundColor(Color.parseColor("#F2F2F2"));
		} else {                 // 默认的item的 颜色
			viewHolder.m_view.setVisibility(View.INVISIBLE);
			viewHolder.tv_content.setTextColor(Color.parseColor("#535353"));
			viewHolder.layout_main.setBackgroundColor(Color.WHITE);
		}
		viewHolder.tv_content.setText(list.get(position).getName());
		return convertView;
	}

	class ViewHolder {
		public RelativeLayout layout_main;
		public View m_view;
		public TextView tv_content;
	}


	public void setIndex(int index) {
		this.index = index;
		notifyDataSetChanged();
	}
}
